#!/usr/bin/env bash
# bash/completion
# ---
# github.com/rafi/.config

# shellcheck disable=1091,1090

# Archlinux loads bash completions from /etc automatically
# https://wiki.archlinux.org/index.php/Bash#Configuration_files

# Deal with other operating-systems...
# macOS / Darwin
if [[ "$OSTYPE" == "darwin"* ]]; then
	# macOS Homebrew bash completions
	if [[ -f "/opt/homebrew/etc/profile.d/bash_completion.sh" ]]; then
		# Load entire Homebrew installed software's bash completion
		# export BASH_COMPLETION_DEBUG=1
		source "/opt/homebrew/etc/profile.d/bash_completion.sh"
	else
		for COMPLETION in "/opt/homebrew/etc/bash_completion.d/"*; do
			[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
		done
	fi

	# Add tab completion for `defaults read|write NSGlobalDomain`
	# You could just use `-g` instead, but I like being explicit
	complete -W "NSGlobalDomain" defaults

	# Add `killall` tab completion for common apps
	complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Twitter" killall

elif [ -f /etc/lsb-release ]; then
	# Ubuntu/Debian manual bash completions loading
	if [ -f /usr/share/bash-completion/bash_completion ]; then
		. /usr/share/bash-completion/bash_completion
	elif [ -f /etc/bash_completion ]; then
		. /etc/bash_completion
	fi
fi

# vim: set ft=sh ts=2 sw=2 tw=80 noet :
